package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.AddressDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Address;
import com.itheima.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = AddressService.class)
@Transactional
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressDao addressDao;
    /**
     * 添加公司地址信息
     */
    @Override
    public void add(Address address) {
        addressDao.add(address);
    }
    /**
     * 分页查询以及模糊查询方法
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        //使用分页查询插件放入相应参数进行查询
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        String queryString = queryPageBean.getQueryString();

        if (queryString!=null&&!"".equals(queryString)){
            queryString = "%"+queryString+"%";
        }
        Page<Address> page = addressDao.findPage(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }
    /**
     * 根据id删除地址信息
     * @param id
     */
    @Override
    public void delete(int id) {
        addressDao.delete(id);
    }
}
